home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9516 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  71 lines

  1. Path: titan.fullerton.edu!grosin
  2. From: grosin@titan.fullerton.edu (Gil Rosin)
  3. Newsgroups: comp.lang.c++
  4. Subject: HELP - templates won't compile via Project files...
  5. Date: 2 Mar 1996 07:24:59 GMT
  6. Organization: California State University at Fullerton
  7. Message-ID: <4h8t4b$oi3@wintermute.ecs.fullerton.edu>
  8. NNTP-Posting-Host: titan.ecs.fullerton.edu
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. The title says it all, I'm a newbie to C++ and wrote a stack package that
  12. just did integers, well, I recently tried to convert it to a template.
  13.  
  14. Anyways, when I try to compile it, I get linker errors saying that the 
  15. functions can not be found, yet they EXIST!
  16.  
  17. I only get those errors for functions that are defined out of line, for example
  18. I have 3 files:
  19.  
  20. STACK.H - class declaration
  21. STACK.CPP - a few STACK functions
  22. TEST.CPP - the driver
  23.  
  24. I have most of the functions defined inline because they are small, but 3
  25. I have out of line, Push, Pop and Flush.
  26.  
  27. Anyways, in stack.h, I define them in the class like:
  28.  
  29. template <class ElementType>
  30. class Stack
  31.  {
  32.   public:
  33.     void Push(const ElementType & Element);
  34.     ElementType Pop(void);
  35.     void Flush(void);
  36.  }
  37.  
  38. then in stack.cpp I include Stack.h, and have the functions defined as:
  39.  
  40. template <class ElementType>
  41. void Stack<ElementType>::Flush(void)
  42.  {
  43.  }
  44.  
  45. template <class ElementType>
  46. void Stack<ElementType>::Push(const ElementType & Element)
  47.  {
  48.  }
  49.  
  50. template <class ElementType>
  51. ElementType Stack<ElementType>::Pop(void)
  52.  {
  53.  }
  54.  
  55. when I compile it in a project file in Borland C++ v3.1, It compiles ok, but
  56. I get 3 linker errors:
  57.  
  58. undefined symbol Flush........
  59. undefined symbol Push.... in TEST.CPP
  60. ....
  61.  
  62. etc. BUT here's the kicker, when I lump all the 3 files into one file and THEN
  63. compile the one file, everything works fine, what is going on here?
  64.  
  65. Please reply via email to grosin@titan.fullerton.edu
  66.  
  67. Thanks.
  68.  
  69. .
  70.  
  71.